package com.sctvcloud.dongqu.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ruihang.generalibrary.ui.adapter.BaseHolderAbsAdapter;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.sctvcloud.dongqu.R;
import com.sctvcloud.dongqu.beans.ADynamicsItem;
import com.sctvcloud.dongqu.ui.adapter.holder.AnchorCircleHolder;

import java.util.List;

/**
 * Created by Administrator on 2017/9/3 0003.
 */

public class AnchorCircleAdapter extends BaseHolderAbsAdapter<ADynamicsItem, AnchorCircleHolder> {
    private OnItemInternalClick playClick;
    /**
     * 此属性必须在{@link android.support.v7.widget.RecyclerView#setAdapter(android.support.v7.widget.RecyclerView.Adapter)}之前设置
     */
    private boolean canDelete;

    public OnItemInternalClick getPlayClick() {
        return playClick;
    }

    public void setPlayClick(OnItemInternalClick playClick) {
        this.playClick = playClick;
    }

    public AnchorCircleAdapter(Context context, List<ADynamicsItem> list) {
        super(context, list);
    }

    @Override
    public AnchorCircleHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_anchor_home_dynamics, parent, false);
        AnchorCircleHolder holder = new AnchorCircleHolder(context, view);
        holder.setInternalClick(this);
        if (canDelete) {
            holder.enableDelete();
        }
        return holder;
    }

    @Override
    public void onBindViewHolder(AnchorCircleHolder holder, int position) {
        super.onBindViewHolder(holder, position);
//        holder.setLastItem(position == data.size() - 1);
    }

    @Override
    public void onItemInternalClick(View itemView, View view, int position) {
        if (playClick != null && view != null && view.getId() == R.id.item_anchor_home_dynamics_video_play) {
            playClick.onItemInternalClick(itemView, view, position);
        } else {
            super.onItemInternalClick(itemView, view, position);
        }
    }

    @Override
    public void onDestory() {
        itemInternalClick=null;
        super.onDestory();
    }

    public void setCanDelete(boolean canDelete) {
        this.canDelete = canDelete;
    }
}
